<template>
  <div class="card-items">
    <div class="head-part">
      <div class="title">
        <img src="@/assets/van-img.png" alt="" />
        <span>{{ dataItem.title }}</span>
      </div>
      <div class="time-box" @click="showDatePicker = true">
        <img src="@assets/pan-view/riqi.png" />
        <div>{{ times }}</div>
      </div>
    </div>

    <div class="tab-btn">
      <span
        v-for="(item, index) in tabList"
        :key="index"
        @click="tabClick(index)"
        :class="tabIndex == index ? 'btn-select' : 'btn-unselect'"
        >{{ item.name }}</span
      >
    </div>

    <moreLineBarPanelItem
      :itemObj="item"
      v-for="(item, index) in chartObjs"
      :key="index"
    ></moreLineBarPanelItem>

    <van-popup v-model:show="showDatePicker" round position="bottom">
      <van-datetime-picker
        v-model="currentDate"
        type="year-month"
        title="选择年月"
        :min-date="minDate"
        :max-date="maxDate"
        :formatter="formatter"
        @cancel="showDatePicker = false"
        @confirm="onDateConfirm"
      />
    </van-popup>
  </div>
</template>
<script>
import { reactive, toRefs, onMounted } from "vue";
// import lineEcharts from "@/components/lineBarEcharts.vue";
import moreLineBarPanelItem from "./moreLineBarPanel-item.vue";
import moment from "moment";
export default {
  components: {
    moreLineBarPanelItem,
  },
  props: ["itemObj"],
  setup(props, { emit }) {
    let itemObj = props.itemObj;
    const state = reactive({
      title: itemObj.title,
      title2: itemObj.title2,
      showDatePicker: false,
      chartObjs: itemObj.chartObjs,
      showPopover: false,
      minDate: new Date(2020, 0, 1),
      maxDate: new Date(2025, 10, 1),
      currentDate: new Date(),
      times: moment().format("YYYYMM"),
      tabList: itemObj.tabList,
      dataItem: props.itemObj,
      tabIndex: 0,
      monthSatisfaction: "4131",
      index1: itemObj.index1,
      //   chartObj: {},
    });
    //一级tab切换
    function tabClick(val) {
      state.tabIndex = val;
      emit("changeMsg", state.tabList[val]);
      if (val == 0) {
        state.monthSatisfaction = "92.24%";
        state.ranking = "24";
      } else {
        state.monthSatisfaction = "96.24%";
        state.ranking = "10";
      }
    }
    const formatter = (type, val) => {
      if (type === "year") {
        return `${val}年`;
      }
      if (type === "month") {
        return `${val}月`;
      }
      return val;
    };

    const onDateConfirm = (value) => {
      state.showDatePicker = false;
      state.times = moment(value).format("YYYYMM");
    };
    const onSelect = (action) => {
      state.selectName = action.text;
      if (state.selectName == "分公司排名") {
      } else {
      }
    };
    onMounted(() => {
      //   state.chartObj = state.dataItem.chartObj;
    });
    return {
      ...toRefs(state),
      tabClick,
      onDateConfirm,
      onSelect,
      formatter,
    };
  },
};
</script>
<style lang="scss" scoped>
.card-items {
  margin: 10px;
  width: calc(100% - 20px);
  //   height: 298px;
  background-color: #fff;
  border-radius: 5px;
  padding: 10px;
  margin-bottom: 10px;
  .head-part {
    // margin: 10px;
    // padding: 10px;
    width: 100%;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    .qs-text {
      padding: 0 15px;
      line-height: 24px;
      color: #666666;
      margin-right: 10px;
      font-size: 12px;
      background: #ffffff;
      box-shadow: 0px 0px 2px 0px rgba(0, 0, 0, 0.2);
      border-radius: 4px;
    }
  }

  .time-box {
    background: #ffffff;
    width: 106px;
    height: 24px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    color: black;
    font-size: 12px;
    box-shadow: 0px 0px 2px 0px rgba(0, 0, 0, 0.2);
    border-radius: 4px;

    img {
      height: 14px;
      width: 14px;
    }
  }
  .title {
    width: 50%;
    display: flex;
    align-items: center;
    span {
      font-size: 16px;
      font-weight: 400;
      color: #333333;
    }
  }

  .value-card {
    margin-top: 10px;
    margin-bottom: 10px;
    width: 100%;
    height: 80px;
    background: url("@assets/pan-view/BG.png") no-repeat 0 0;
    background-size: 100% 100%;
    border-radius: 4px;

    .title-box {
      padding: 10px;
      display: flex;
      justify-content: space-around;

      .left {
        width: 80%;

        .title {
          width: 100%;
          font-size: 14px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #ffffff;
          line-height: 20px;
        }

        .line {
          width: 16px;
          height: 4px;
          background: rgba(255, 255, 255, 0.7);
          border-radius: 2px;
          border: 0px solid #979797;
        }
      }

      .rank {
        display: flex;
        width: 72px;
        height: 20px;
        background: #fffaf4;
        border-radius: 4px;
        font-size: 12px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #333333;
        line-height: 16px;
        align-items: center;
        justify-content: center;
      }
    }

    .value-box {
      display: flex;
      width: 100%;
      justify-content: space-around;
      .item-value {
        display: flex;
        width: 40%;
        justify-content: start;

        .title {
          width: 50px;
          font-size: 10px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #ffffff;
          line-height: 14px;
        }

        .value {
          font-size: 21px;
          font-family: Helvetica-Bold, Helvetica;
          font-weight: bold;
          color: #ffffff;
          line-height: 24px;
        }
      }
    }
  }
  .tab-btn {
    width: calc(100% - 8px);
    display: flex;
    flex-direction: row;
    align-items: center;
    margin: 8px 0 0 8px;
    overflow-x: auto;
    .btn-select {
      padding: 6px 13px;
      background: linear-gradient(285deg, #fe6800 0%, #ff9900 100%);
      border-radius: 12px;
      color: #ffffff;
      white-space: nowrap;
      font-size: 13px;
      margin-right: 4px;
    }
    .btn-unselect {
      padding: 6px 13px;
      background: #f3f3f3;
      border-radius: 12px;
      color: #333333;
      white-space: nowrap;
      font-size: 13px;
      margin-right: 4px;
    }
  }

  .tab-btn::-webkit-scrollbar {
    width: 0;
    height: 0;
  }
  .desc-panel {
    width: 100%;
    margin-top: 20px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    .left-desc {
      font-size: 14px;
      .text1 {
        font-size: 14px;
        font-weight: 400;
        color: #333333;
        margin-right: 6px;
      }
      .text2 {
        font-size: 21px;
        font-weight: bold;
        color: #333333;
        margin-right: 6px;
      }
    }

    .right-box {
      display: flex;
      margin-right: 10px;

      .right-desc1 {
        padding: 0 10px;
        height: 24px;
        line-height: 24px;
        background: #f3f3f3;
        color: #333333;
        border-radius: 4px;
        font-size: 12px;
        text-align: center;
      }

      .right-desc {
        padding: 0 10px;
        height: 24px;
        line-height: 24px;
        background: #fff0dc;
        color: #333333;
        border-radius: 4px;
        font-size: 12px;
        text-align: center;
      }
    }
  }
}
</style>
